#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

import sys

infile = open(sys.argv[1], "r")
max_count = int(sys.argv[2])
prefix = sys.argv[1][:sys.argv[1].rindex(".")]

file_index = 1
count = 0

outfile = open(prefix + "_" + str(file_index) + ".txt", "w")
for line in infile:
    outfile.write(line)
    outfile.flush()
    count += 1
    if count == max_count:
        outfile.close()
        count = 0
        file_index += 1
        outfile = open(prefix + "_" + str(file_index) + ".txt", "w")
outfile.close()
